package cn.gson.fengboot.model.service;

import cn.gson.fengboot.model.dao.LxsfyDao;
import cn.gson.fengboot.model.mapper.LxsfyMapper;
import cn.gson.fengboot.model.pojos.Lxsfy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor =  Exception.class)
public class LxsfyService {
    @Autowired
    LxsfyDao lxsfyDao;
    @Autowired
    LxsfyMapper lxsfyMapper;

    //查询销售费用记录
    public List<Lxsfy> cxxsfy( String search, String fenlei){
        return lxsfyMapper.cxxsfy(search,fenlei);
    }

    @Transactional(transactionManager = "transactionManager")
    //新增销售费用记录
    public  void addlxsfy(Lxsfy lxsfy){
        lxsfyDao.save(lxsfy);

    }

    //柱形统计图客人员分布查询
    public Map<String ,Object> xsfyfb(){
        List<Lxsfy> lxname=lxsfyMapper.xsfyfb();
        Map<String,Object> map=new HashMap<>();
        List<String> shul1 =new ArrayList<>();//
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getEmpId().getEmpName());
            shul.add(lxsfyDao.xsfyfb(lxname.get(i).getEmpId().getEmpName()));
        }
        map.put("shul",shul);
        map.put("shul1",shul1);
        return map;
    }

    //圆形统计图费用类别分布查询
    public Map<String ,Object> xsfylbfb(){
        List<Lxsfy> lxname=lxsfyMapper.xsfylbfb();
        Map<String,Object> map=new HashMap<>();
        List<String> shul1 =new ArrayList<>();//
        List<Integer> shul=new ArrayList<>();//数量
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getXsfyLb());
            shul.add(lxsfyDao.xsfylbfb(lxname.get(i).getXsfyLb()));
        }
        map.put("shul",shul);
        map.put("shul1",shul1);
        return map;
    }



    //柱形统计图员工费用统计
    public Map<String ,Object> ygfytj(){
        List<Lxsfy> lxname=lxsfyMapper.xsfyfb();
        Map<String,Object> map=new HashMap<>();
        List<String> shul1 =new ArrayList<>();//
        List<List<Integer>> shull=new ArrayList<>();//员工姓名
        List<Integer> shul=new ArrayList<>();//员工所有销售费用
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getEmpId().getEmpName());
            shull.add(lxsfyDao.ygfytj(shul1.get(i)));
        }
        map.put("shul1",shul1);
        map.put("shull",shull);
        int c =shull.size();
        int[] arr = new int[shull.size()];
        for(int i=0;i<shull.size();i++){
            int d=0;
            int v = shull.get(i).size();
            for(int j=0 ; j<v;j++){
                d +=shull.get(i).get(j);
            }
            arr[i]=d;
            System.out.println(d);
        }
        map.put("shull",arr);//员工销售费用总和
        System.out.println(map);
        return map;
    }


    //对应客户费用统计
    public Map<String ,Object> dykhxsfy(){
        List<Lxsfy> lxname=lxsfyMapper.dykh();
        Map<String,Object> map=new HashMap<>();
        List<String> shul1 =new ArrayList<>();//
        List<List<Integer>> shull=new ArrayList<>();//客户姓名
        List<Integer> shul=new ArrayList<>();//对应客户销售费用
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getXsfyKh());
            shull.add(lxsfyDao.dykhxsfy(shul1.get(i)));
        }
        map.put("shul1",shul1);
        map.put("shull",shull);
        int[] arr = new int[shull.size()];
        for(int i=0;i<shull.size();i++){
            int d=0;
            int v = shull.get(i).size();
            for(int j=0 ; j<v;j++){
                d +=shull.get(i).get(j);
            }
            arr[i]=d;
            System.out.println(d);
        }
        map.put("shull",arr);//员工销售费用总和
        System.out.println(map);
        return map;
    }


    //类别费用统计
    public Map<String ,Object> lbfytj(){
        List<Lxsfy> lxname=lxsfyMapper.xsfylbfb();
        Map<String,Object> map=new HashMap<>();
        List<String> shul1 =new ArrayList<>();//
        List<List<Integer>> shull=new ArrayList<>();//客户姓名
        List<Integer> shul=new ArrayList<>();//对应客户销售费用
        for(int i=0;i<lxname.size();i++){
            shul1.add(lxname.get(i).getXsfyLb());
            shull.add(lxsfyDao.zxfylb(shul1.get(i)));
        }
        map.put("shul1",shul1);
        map.put("shull",shull);
        int[] arr = new int[shull.size()];
        for(int i=0;i<shull.size();i++){
            int d=0;
            int v = shull.get(i).size();
            for(int j=0 ; j<v;j++){
                d +=shull.get(i).get(j);
            }
            arr[i]=d;
            System.out.println(d);
        }
        map.put("shull",arr);//员工销售费用总和
        System.out.println(map);
        return map;
    }

}
